package aa.jx.order.controller;

import aa.jx.order.model.PaymentInfo;
import aa.jx.order.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/payments")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @PostMapping
    public PaymentInfo createPayment(@RequestParam Long orderId) {
        return paymentService.createPayment(orderId);
    }

    @PostMapping("/{paymentId}/process")
    public void processPayment(@PathVariable Long paymentId,
                               @RequestParam boolean success) {
        paymentService.processPayment(paymentId, success);
    }

    @GetMapping("/{paymentId}")
    public PaymentInfo getPaymentInfo(@PathVariable Long paymentId) {
        return paymentService.getPaymentInfo(paymentId);
    }

    @GetMapping("/by-order/{orderId}")
    public PaymentInfo getPaymentByOrderId(@PathVariable Long orderId) {
        return paymentService.getPaymentByOrderId(orderId);
    }

    @PostMapping("/{paymentId}/cancel")
    public void cancelPayment(@PathVariable Long paymentId) {
        paymentService.cancelPayment(paymentId);
    }
}